<template>
<el-row>
  <el-col :xl="5" :lg="8" :md="12" :sm="12" :xs="24">
    <el-form :model="form" ref="form" label-width="90px" size="small" :rules="rules">
      <!-- <el-form-item label="终端号码：" prop="term_no">
        <el-input v-model="form.term_no" :maxlength="10"></el-input>
      </el-form-item> -->
      <el-form-item label="机构号码：" prop="org_no">
        <el-input v-model="form.org_no" :maxlength="10"></el-input>
      </el-form-item>
      <el-form-item label="进件秘钥：" prop="enter_key">
        <el-input type="textarea" :rows="5" v-model="form.enter_key" :maxlength="40"></el-input>
      </el-form-item>
      <!-- <el-form-item label="交易秘钥：" prop="pay_key">
        <el-input type="textarea" :rows="5" v-model="form.pay_key" :maxlength="40"></el-input>
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" class="fr" @click="handleClickSubmit">确认保存</el-button>
      </el-form-item>
    </el-form>
  </el-col>
</el-row>
</template>

<script>
import { channelStarposSetting, channelStarposSetUpdate } from '@/api/setting'

export default {
  data() {
    return {
      form: {
        term_no: '',
        org_no: '',
        enter_key: '',
        pay_key: ''
      },
      rules: {
        term_no: [{ required: true, trigger: 'blur', message: '必须填写哦~' }],
        org_no: [{ required: true, trigger: 'blur', message: '必须填写哦~' }],
        enter_key: [{ required: true, trigger: 'blur', message: '必须填写哦~' }],
        pay_key: [{ required: true, trigger: 'blur', message: '必须填写哦~' }]
      }
    }
  },
  methods: {
    handleDocumentInit() {
      channelStarposSetting().then(res => {
        if (res.data.errorCode === 0) {
          // this.form.term_no = res.data.result.term_no
          this.form.org_no = res.data.result.org_no
          this.form.enter_key = res.data.result.enter_key
          // this.form.pay_key = res.data.result.pay_key
        } else {
          this.$message.error(res.data.errorMsg)
        }
      })
    },
    handleClickSubmit() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          channelStarposSetUpdate(this.form).then(res => {
            if (res.data.errorCode === 0) {
              this.$message.success(res.data.errorMsg)
            } else {
              this.$message.error(res.data.errorMsg)
            }
          })
        }
      })
    }
  },
  created() {
    this.handleDocumentInit()
  }
}
</script>